import requests


def verify_setup():
    """验证环境配置"""
    print("🔍 检查RAG Multi-hop环境配置...")

    # 1. 检查Ollama服务
    try:
        response = requests.get("http://localhost:11434/api/tags", timeout=5)
        if response.status_code == 200:
            print("✅ Ollama服务运行正常")
            models = response.json().get("models", [])
            print(f"📋 可用模型: {[m.get('name') for m in models]}")
        else:
            print(f"❌ Ollama服务响应异常: {response.status_code}")
    except Exception as e:
        print(f"❌ 无法连接Ollama服务: {e}")
        print("💡 请运行: ollama serve")
        return False

    # 2. 检查deepseek模型
    try:
        test_payload = {
            "model": "deepseek:1.5b",
            "prompt": "Hello",
            "stream": False
        }
        response = requests.post(
            "http://localhost:11434/api/generate",
            json=test_payload,
            timeout=30
        )
        if response.status_code == 200:
            print("✅ deepseek:1.5b 模型工作正常")
        else:
            print(f"❌ 模型测试失败: {response.status_code}")
            print("💡 请运行: ollama pull deepseek:1.5b")
    except Exception as e:
        print(f"❌ 模型测试异常: {e}")
        return False

    # 3. 检查Python依赖
    try:
        import faiss
        import sentence_transformers
        print("✅ Python依赖包正常")
    except ImportError as e:
        print(f"❌ 缺少依赖包: {e}")
        return False

    print("🎉 环境配置验证完成！")
    return True


# 在main函数开始前调用
if __name__ == "__main__":
    if verify_setup():
        print("验证成功！！！")
    else:
        print("请解决上述问题后重试")